const app = getApp();
const http = require('../../../utils/http.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    pageSize: 15,
    tradeList: [],
    time:null,
    customer:null
  },

  selectTradeList(time) {
    http.get('/api/merchant/selectTradeList', {pageNum: 1, pageSize: this.data.pageSize, createdDate: time}).then(res => {
      if (res.code == 200) {
        this.setData({
          tradeList: res.data.list,
          nextPage:res.data.nextPage,
          pageNum:2
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('aaaaa')
    this.setData({
      customer: app.globalData.customer
    })
    console.log(options.time)
    this.setData({
      time:options.time
    })
    this.selectTradeList(options.time)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("上拉分页")
    var list = this.data.tradeList
    const that = this
    wx.showLoading({
      title: '加载中。。。',
      mask: true
    })
    if (this.data.nextPage) {
      http.get('/api/merchant/selectTradeList', {pageNum: this.data.pageNum, pageSize: this.data.pageSize, createdDate: this.data.time}).then(res => {
        wx.hideLoading()
        if (res.code == 200) {
          this.setData({
            pageNum: res.data.pageNum + 1,
            nextPage: res.data.nextPage,
            tradeList: list.concat(res.data.list)
          })
          wx.hideLoading()
        }
      })
    } else {
      wx.hideLoading()
      wx.showToast({
        title: '没有更多数据',
        icon: "none"
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
